package cn.dubito.learning.security.core.validator.processor.impl;

import cn.dubito.learning.security.core.validator.code.ValidateCode;
import cn.dubito.learning.security.core.validator.code.sms.SmsCodeSender;
import cn.dubito.learning.security.core.validator.processor.AbstractValidateCodeProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.context.request.ServletWebRequest;

/**
 * 短信验证码发送处理器
 *
 * @author liliang
 * @description:
 * @date 2018/5/8.
 */
//@Component("smsCodeProcessor")
public class SmsCodeProcessor extends AbstractValidateCodeProcessor<ValidateCode> {

//    @Autowired
    private SmsCodeSender smsCodeSender;

    @Override
    protected void send(ServletWebRequest request, ValidateCode validateCode) throws Exception {
        String mobile = ServletRequestUtils.getRequiredStringParameter(request.getRequest(), "mobile");
        // 发送短信
        smsCodeSender.send(mobile, validateCode.getCode());
    }
}
